package it.oneb.study.hibernate;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.cfg.Configuration;

public class hibernateMain
{

	/**
	 * @param args
	 */
	public static void main(String[] args)
	{
		// 1. 默认的构造函数读取hibernate.cfg.xml文件
		Configuration configuration = new Configuration().configure();
		// 2. 获取sessionFactory
		SessionFactory sessionFactory = configuration.buildSessionFactory();
		// 3. 获取session
		Session session = sessionFactory.openSession();
		// 4. 打开事务
		Transaction transaction = session.beginTransaction();
		
		// 5. 操作实体
		User user = new User();
		user.setName("yukin2");
		
		// 6. 保存实体
		session.save(user);
		
		// 7. 事务提交
		transaction.commit();
		
		// 8. 关闭会话
		session.clear();


	}

}
